Page({
  data: {
    allCate:[],
    activeTab:0,
    query:{
      limit:100,
      page:1
    },
    detailData:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
    this.onClickTab(options.index)
    this.getAllCate()
    this.cateid = options.id
    this.getArticleDetail()
  },
 
  async getArticleDetail(){
    const {errno,data} = await wx.http.get('/index/list',{...this.data.query,cateid:this.cateid})
    if(errno !==0) return wx.utils.toast()
    this.setData({detailData:data.list.data})
  
  },
  async getAllCate(){
    const {errno,data} = await  wx.http.get('/index/index')
    if(errno !==0) return wx.utils.toast()
    this.setData({allCate:data.allCate})
  },
  // 跳转页面
  onClickTab(index){
    this.setData({
      activeTab:+index
    })
  },
  onClick(event){
    const selectedTabIndex = event.detail.index;
    const selectedTabId = this.data.allCate[selectedTabIndex].id;
    this.cateid = selectedTabId
    this.getArticleDetail()
  },
})